﻿using System;
using System.Text;
using FortuneUniverse.Fortune.Algorithms;
using Newtonsoft.Json;

namespace FortuneUniverse.Fortune.Dyson
{
  public class StarData
  {
    public int seed;
    public int index;
    public int id;
    public string name = string.Empty;
    public string overrideName = string.Empty;
    [JsonIgnore]
    public VectorLF3 position = VectorLF3.zero;
    [JsonIgnore]
    public VectorLF3 uPosition;
    public float mass = 1f;
    public float lifetime = 50f;
    public float age;
    public EStarType type;
    public float temperature = 8500f;
    public ESpectrType spectr;
    public float classFactor;
    public float color;
    public float luminosity = 1f;
    public float radius = 1f;
    public float acdiskRadius;
    public float habitableRadius = 1f;
    public float lightBalanceRadius = 1f;
    public float dysonRadius = 10f;
    public float orbitScaler = 1f;
    public float asterBelt1OrbitIndex;
    public float asterBelt2OrbitIndex;
    public float asterBelt1Radius;
    public float asterBelt2Radius;
    public int planetCount;
    public float level;
    public float resourceCoef = 1f;
    public PlanetData[] planets;
    public const double kEnterDistance = 3600000.0;
    public const float kPhysicsRadiusRatio = 1200f;
    public const float kViewRadiusRatio = 800f;

    public string displayName => string.IsNullOrEmpty(this.overrideName) ? this.name : this.overrideName;

    public float dysonLumino => Mathf.Round((float) Math.Pow((double) this.luminosity, 0.330000013113022) * 1000f) / 1000f;

    public float systemRadius
    {
      get
      {
        float num = this.dysonRadius;
        if (this.planetCount > 0)
          num = this.planets[this.planetCount - 1].sunDistance;
        return num;
      }
    }

    public float physicsRadius => this.radius * 1200f;

    public float viewRadius => this.radius * 800f;

    public string typeString
    {
      get
      {
        string str = string.Empty;
        if (this.type == EStarType.GiantStar)
          str = this.spectr > ESpectrType.K ? (this.spectr > ESpectrType.F ? (this.spectr != ESpectrType.A ? str + "蓝巨星".Translate() : str + "白巨星".Translate()) : str + "黄巨星".Translate()) : str + "红巨星".Translate();
        else if (this.type == EStarType.WhiteDwarf)
          str += "白矮星".Translate();
        else if (this.type == EStarType.NeutronStar)
          str += "中子星".Translate();
        else if (this.type == EStarType.BlackHole)
          str += "黑洞".Translate();
        else if (this.type == EStarType.MainSeqStar)
          str = str + this.spectr.ToString() + "型恒星".Translate();
        return str;
      }
    }

    public long Iron => this.GetResourceAmount(1);

    public long Copper => this.GetResourceAmount(2);

    public long Silicium => this.GetResourceAmount(3);

    public long Titanium => this.GetResourceAmount(4);

    public long Stone => this.GetResourceAmount(5);

    public long Coal => this.GetResourceAmount(6);

    public long Oil => this.GetResourceAmount(7);

    public long Fireice => this.GetResourceAmount(8);

    public long Diamond => this.GetResourceAmount(9);

    public long Fractal => this.GetResourceAmount(10);

    public long Crysrub => this.GetResourceAmount(11);

    public long Grat => this.GetResourceAmount(12);

    public long Bamboo => this.GetResourceAmount(13);

    public long Mag => this.GetResourceAmount(14);

    public long IronSpots => (long) this.GetResourceSpots(1);

    public long CopperSpots => (long) this.GetResourceSpots(2);

    public long SiliciumSpots => (long) this.GetResourceSpots(3);

    public long TitaniumSpots => (long) this.GetResourceSpots(4);

    public long StoneSpots => (long) this.GetResourceSpots(5);

    public long CoalSpots => (long) this.GetResourceSpots(6);

    public long OilSpots => (long) this.GetResourceSpots(7);

    public long FireiceSpots => (long) this.GetResourceSpots(8);

    public long DiamondSpots => (long) this.GetResourceSpots(9);

    public long FractalSpots => (long) this.GetResourceSpots(10);

    public long CrysrubSpots => (long) this.GetResourceSpots(11);

    public long GratSpots => (long) this.GetResourceSpots(12);

    public long BambooSpots => (long) this.GetResourceSpots(13);

    public long MagSpots => (long) this.GetResourceSpots(14);

    public double PositionX => this.position.x;

    public double PositionY => this.position.y;

    public double PositionZ => this.position.z;

    public double Distance => this.position.magnitude;

    public string PlanetsType
    {
      get
      {
        StringBuilder stringBuilder = new StringBuilder(256);
        for (int index = 0; index < this.planetCount; ++index)
        {
          if (index != 0)
            stringBuilder.Append(',');
          stringBuilder.Append((object) this.planets[index].type);
        }
        return stringBuilder.ToString();
      }
    }

    public string PlanetsTypeString
    {
      get
      {
        StringBuilder stringBuilder = new StringBuilder(256);
        for (int index = 0; index < this.planetCount; ++index)
        {
          if (index != 0)
            stringBuilder.Append(',');
          stringBuilder.Append(this.planets[index].typeString);
        }
        return stringBuilder.ToString();
      }
    }

    public string PlanetsSingularity
    {
      get
      {
        StringBuilder stringBuilder = new StringBuilder(256);
        for (int index = 0; index < this.planetCount; ++index)
        {
          if (index != 0)
            stringBuilder.Append('|');
          if (this.planets[index].singularity != EPlanetSingularity.None)
            stringBuilder.Append((object) this.planets[index].singularity);
        }
        return stringBuilder.ToString();
      }
    }

    public int PlanetCount => this.planetCount;

    public long GetResourceAmount(int type)
    {
      long num = 0;
      for (int index = 0; index < this.planetCount; ++index)
      {
        PlanetData planet = this.planets[index];
        if (planet.type != EPlanetType.Gas)
          num += planet.veinAmounts[type];
      }
      return num;
    }

    public int GetResourceSpots(int type)
    {
      int num = 0;
      for (int index = 0; index < this.planetCount; ++index)
      {
        PlanetData planet = this.planets[index];
        if (planet.type != EPlanetType.Gas && planet.veinSpotsSketch != null)
          num += planet.veinSpotsSketch[type];
      }
      return num;
    }

    public string OrbitsDescString()
    {
      string str = string.Empty;
      for (int index1 = 1; index1 <= 12; ++index1)
      {
        int num = 0;
        for (int index2 = 0; index2 < this.planetCount; ++index2)
        {
          if (this.planets[index2].orbitAround == 0 && this.planets[index2].orbitIndex == index1)
          {
            num = this.planets[index2].number;
            break;
          }
        }
        str = (double) this.asterBelt1OrbitIndex != (double) index1 ? ((double) this.asterBelt2OrbitIndex != (double) index1 ? str + num.ToString() : str + "b") : str + "a";
      }
      return str;
    }
  }
}
